window.onload = function () {
    document.getElementById("administrative").className = "add-nav-active";
    document.getElementById("issue").className = "add_class";
    document.getElementById("issue_approval_ul").style.display = "inline-block";
    document.getElementById("jiantou3").className = "iconfont icon-jiantou-xia";
    document.getElementById("organizational_management_ul").style.display = "none";
    upload_issue_file1()
};



function click_ul() {
    if (document.getElementById("jiantou").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou").className = "iconfont icon-jiantou-xia";
        document.getElementById("organizational_management_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou").className = "iconfont icon-jiantou-shang";
        document.getElementById("organizational_management_ul").style.display = "none";
    }
}

function click_ul1() {
    if (document.getElementById("jiantou1").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou1").className = "iconfont icon-jiantou-xia";
        document.getElementById("gebruikersrol_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou1").className = "iconfont icon-jiantou-shang";
        document.getElementById("gebruikersrol_ul").style.display = "none";
    }
}

function click_ul2() {
    if (document.getElementById("jiantou2").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou2").className = "iconfont icon-jiantou-xia";
        document.getElementById("meeting_management_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou2").className = "iconfont icon-jiantou-shang";
        document.getElementById("meeting_management_ul").style.display = "none";
    }
}

function click_ul3() {
    if (document.getElementById("jiantou3").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou3").className = "iconfont icon-jiantou-xia";
        document.getElementById("issue_approval_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou3").className = "iconfont icon-jiantou-shang";
        document.getElementById("issue_approval_ul").style.display = "none";
    }
}

// 更改发文字号
function get_option() {
    var myselect = document.getElementById("number_type");
    var index = myselect.selectedIndex;　　　　　　　　　//获取被选中的索引
    var number_type = myselect.options[index].value;　　　　　　//获取被选中的值
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/administrative/document.html", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send("number_type="+String(number_type));
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                document.getElementById("dispatch-size").innerHTML = JsonDate["data"][0]["serial_definition"];
            }
        }
    };
}



// 选择流程执行人弹框
function entrust() {
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/technological/delegation", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                var JsonDate = JSON.parse(xhr.responseText);
                console.log(JsonDate);
                window.personnel_list = JsonDate["data"];
                var department_list = document.getElementById("department_list");
                department_list.innerHTML = "";
                var ul_tag = document.createElement("ul");
                for (var i=0; i<JsonDate["branch_list"].length; i++) {
                    var li_tag = document.createElement("li");
                    li_tag.innerHTML = JsonDate["branch_list"][i];li_tag.setAttribute("onclick", "choice_peopel('"+JsonDate["branch_list"][i]+"')");li_tag.className="li-class";
                    ul_tag.appendChild(li_tag);
                    department_list.appendChild(ul_tag);
                }
            }
        }
    };
}



// 创建右侧选择人员列表
function choice_peopel(choice_key) {
    var personnel_list = window.personnel_list;
    document.getElementById("img-display1").style.display = "none";
    var t_table = document.getElementById("t_table2");
    deltr1();
    for (var i=0; i<personnel_list[choice_key].length; i++) {
        var tr = document.createElement("tr");
        var td = document.createElement("td");var td1 = document.createElement("td");var td2 = document.createElement("td");
        td.innerHTML = "<input id='"+personnel_list[choice_key][i]+"' class='check_box' type=\"checkbox\" onclick='choice_consignor(this.id)'>";td.style.textAlign = "center";
        td1.innerHTML = i+1;td1.style.textAlign = "center";
        td2.innerHTML = personnel_list[choice_key][i];td2.title =personnel_list[choice_key][i];td2.style.textAlign = "center";

        tr.appendChild(td);tr.appendChild(td1);tr.appendChild(td2);
        t_table.appendChild(tr);
    }
}


// 删除列表
function deltr1(){
    var tb = document.getElementById('t_table2');
    var rowNum=tb.rows.length;
    for (i=0;i<rowNum;i++) {
        tb.deleteRow(i);
        rowNum=rowNum-1;
        i=i-1;
    }
}



// 选择委托人
function choice_consignor(ele_id) {
     // var checked_label = document.getElementById("checked-label");
     // var span = document.createElement("span");
     // span.innerHTML = ele_id;span.style.marginLeft="1%";
     // checked_label.appendChild(span);
    check_more_one_not(ele_id);
    document.getElementById("checked-label").innerHTML = "<span style='margin-left: 1%;'>"+ele_id+"</span>";
}

// checkBox不允许多选
function check_more_one_not(ele_id) {
    var check_box_list = document.getElementsByClassName("check_box");
    for (var i=0; i<check_box_list.length; i++){
        if (String(check_box_list[i].id) !== String(ele_id)){
            document.getElementById(check_box_list[i].id).checked = false;
        }else {
            document.getElementById(check_box_list[i].id).checked = true;
        }
    }
}


function upload_issue() {
    document.getElementById("loading").style.display = "inline-block";
    var form = new FormData();
    var issue_number = document.getElementById("issue_number").innerHTML;
    form.append("issue_number", issue_number);
    var submission_department = document.getElementById("submission_department").innerHTML;
    form.append("submission_department", submission_department);

     var submission_date = document.getElementById("submission_date").innerHTML;
    form.append("submission_date", submission_date);

     var topics = document.getElementById("topics").innerText;
    form.append("topics", topics);

     var key_issues = document.getElementById("key_issues").innerText;
    form.append("key_issues", key_issues);

    var leader_opinion = document.getElementById("leader_opinion").innerText;
    form.append("leader_opinion", leader_opinion);

    var processing_result = document.getElementById("processing_result").innerText;
    form.append("processing_result", processing_result);

    var childNodes_list1 = document.getElementById("jointly").rows.length;
    console.log('childNodes_list:',childNodes_list1)
    var co_department_li = []
    for (var i=0; i<childNodes_list1; i++) {
        console.log(i)
        co_id = 'is_department' + (i+1)
        console.log('co_id:',co_id)
        var co_department_text = document.getElementById(co_id).innerText;
        console.log('co_department_text:',co_department_text)
        co_department_li.push(co_department_text);
    }
    console.log('co_department_li:',co_department_li)
    form.append("co_department_li", co_department_li);




    // if(document.getElementById("a").style.display==='none'){
    //     var issue_sketch_text = '0';
    // }
    // else{
    //     var issue_sketch_text = document.getElementById("issue_sketch_text").innerHTML;
    // }
    // form.append("issue_sketch_text", issue_sketch_text);
    //
    // if(document.getElementById("c").style.display==='none'){
    //     var issue_sketch_text2 = '0';
    // }
    // else{
    //     var issue_sketch_text2 = document.getElementById("issue_sketch_text2").innerHTML;
    // }
    // form.append("issue_sketch_text2", issue_sketch_text2);
    //
    // if(document.getElementById("e").style.display==='none'){
    //     var issue_sketch_text3 = '0';
    // }
    // else{
    //     var issue_sketch_text3 = document.getElementById("issue_sketch_text3").innerHTML;
    // }
    // form.append("issue_sketch_text3", issue_sketch_text3);
    //
    // if(document.getElementById("g").style.display==='none'){
    //     var issue_sketch_text4 = '0';
    // }
    // else{
    //     var issue_sketch_text4 = document.getElementById("issue_sketch_text4").innerHTML;
    // }
    // form.append("issue_sketch_text4", issue_sketch_text4);

    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/administrative/issue.html", true);
    xhr.send(form);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                alert(JsonDate['message'])
                if (JsonDate['code'] === 200){
                     window.location.href="/administrative/my_issue.html";
                }
                // creat_table(JsonDate["data"][0])

            }
        }
    };
}

function but_click() {
             bdhtml=document.getElementById("print_div").innerHTML;
             sprnstr="<!--startprint-->";   //开始打印标识字符串有17个字符
             eprnstr="<!--endprint-->";        //结束打印标识字符串
             prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); //从开始打印标识之后的内容
             prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//截取开始标识和结束标识之间的内容
             var iframe = null;
             iframe = document.getElementById("iframe1");

             var htmlToPrint = '' +
            '<style type="text/css">' +
                'table {'+
                    'border-collapse:collapse;' +
                '}' +
                'table td{'+
                    'border-top: 1px solid red;'+
                    'border-left: 1px solid red;'+
                    'border-bottom: 1px solid red;'+
                    'border-right: 1px solid red;'+
                    'border-collapse: separate;'+
                '}'+
            '</style>';
             htmlToPrint += prnhtml
             var iwindow = null;
             var iwindow = iframe.contentWindow;//获取iframe的window对象
             iwindow.document.close();
             iwindow.document.write(htmlToPrint);
             iwindow.print(); //调用浏览器的打印功能打印指定区域
         }



// 点击获取当前节点及所有子节点
function treenodeClick(event, treeId, treeNode, clickFlag) {
    //此处treeNode 为当前节点
    var str ='' ;
    str = getAllChildrenNodes(treeNode,str);
    // 去掉最前面的逗号
    str = str.substring(1, str.length);
    // 加上被选择节点自己
    var count = treeNode.name + ',' + str;
    // 得到所有节点ID 的数组
    var countArray = str.split(',');

    // 点击之后的业务流程
    var Ztree_label = document.getElementById("Ztree-label");
    Ztree_label.innerHTML = "";
    document.getElementById("checkboxID").checked = false;
    var ul = document.createElement("ul");
    var li = document.createElement("li");
    ul.setAttribute("id", "label-ul");
    li.className = "model_li";
    li.style.display = "inline-block";
    li.setAttribute("onclick", "click_val(this)");
    li.setAttribute("value", treeNode.name);
    li.innerHTML = treeNode.name;
    ul.appendChild(li);

    for (var i=0; i<countArray.length; i++) {
        var li1 = document.createElement("li");
        li1.className = "model_li";
        li1.setAttribute("onclick", "click_val(this)");
        li1.setAttribute("value", countArray[i]);
        li1.innerHTML = countArray[i];
        ul.appendChild(li1);
    }
    Ztree_label.appendChild(ul);
    document.getElementById("checked-label").innerHTML = "";

}

// 递归，获取所有子节点
function getAllChildrenNodes(treeNode,result){
    if (treeNode.isParent) {
        var childrenNodes = treeNode.children;
        if (childrenNodes) {
            for (var i = 0; i < childrenNodes.length; i++) {
                result += ',' + childrenNodes[i].name;
                result = getAllChildrenNodes(childrenNodes[i], result);
            }
        }
    }
    return result;
}

// 点击标签选中
function click_val(event) {
    var model_li_list = document.getElementsByClassName("model_li");
    for (var i=0; i<model_li_list.length; i++) {
        model_li_list[i].style.color = "#3f414d";
    }
    event.style.color = "#4169E1";
    var checked_label = document.getElementById("checked-label");
    checked_label.innerHTML = "";
    var p_tag = document.createElement("p");
    p_tag.setAttribute("id", "checked_ptag");
    p_tag.style.cursor = "pointer";
    p_tag.innerHTML = event.innerText;
    p_tag.style.color = "#3f414d";
    checked_label.appendChild(p_tag);
}

// 删除模态框选中的节点
function delete_val(id) {
    // 创建左侧架构目录
    console.log(id)

    document.getElementById("Ztree-label").innerHTML = "";
    document.getElementById("checked-label").innerHTML = "";
    document.getElementById("checkboxID").checked = false;
    document.getElementById("co_department_id").innerHTML = id;
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/administrative/query_department.html", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                console.log(JsonDate)
                window.JSONObject = JsonDate["data"][0]["check_dict"];
                create_left_catalog(JsonDate["data"][0]["tree_data"], "model");
            }
        }
    };
}


// 检查复选框的选择状态
function check_input() {
    var model_li_list = document.getElementsByClassName("model_li");
    if(document.getElementById("checkboxID").checked){
        for (var i=0; i<model_li_list.length; i++) {
            model_li_list[i].style.display = "inline-block";
        }
    }else {
        for (var t=1; t<model_li_list.length; t++) {
            model_li_list[t].style.display = "none";
        }
    }
}

// 点击模态框确认按钮选择上级部门
function summit_val() {
    if (document.getElementById("checked_ptag")){
        var CoOrganizingDepartment = document.getElementById("checked_ptag").innerText; // 协办部门
        console.log(CoOrganizingDepartment);
        co_department_id =  document.getElementById("co_department_id").innerText;
        document.getElementById(co_department_id).innerHTML = CoOrganizingDepartment+"<div id='"+co_department_id+"_chose' style=\"color:blue;display: none\"  data-toggle=\"modal\" data-target=\".bd-example-modal-xl\" onclick=\"delete_val('"+co_department_id+"')\">\n" +
            "                                        选择\n" +
            "                                    </div>\n" +
            "\n" +
            "                                    <div id='"+co_department_id+"_del' style=\"display: none\" onclick=\"del_co('"+co_department_id+"')\">\n" +
            "                                        删除\n" +
            "                                    </div>";
        document.getElementById("model-close").click();
    }else {
        alert("请选择部门！")
    }
}

// 删除部门
function del_dep(ele_id) {
    document.getElementById("loading").style.display = "inline-block";
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/system-setup/organization.html", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send("dep_id="+String(ele_id));
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                window.JSONObject = JsonDate["data"][0]["check_dict"];
                create_left_catalog(JsonDate["data"][0]["tree_data"]);
                // 给部门名称赋值
                document.getElementById('industry_title').value = "";
                // 给上级部门赋值
                document.getElementById('superior_department').value = "";
                // 给部门负责人赋值
                document.getElementById('principal').value = "";
                document.getElementById("loading").style.display = "none";
            }
        }
    };
}

// 创建左侧架构目录
function create_left_catalog(zNodes, create_location) {
    create_location = create_location || "none";
    if (create_location === "model") {
        var setting = {
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                onClick: treenodeClick
            }
        };
        $.fn.zTree.init($("#treeDemo1"), setting, zNodes);
    }else {
        var setting1 = {
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                onClick: treenodeClick1
            }
        };
        $.fn.zTree.init($("#treeDemo"), setting1, zNodes);
    }
}


// 点击获取当前节点及所有子节点
function treenodeClick1(event, treeId, treeNode, clickFlag) {
    // 给部门名称赋值
    document.getElementById('industry_title').value = JSONObject[String(treeNode.id)][0];
    // 给上级部门赋值
    document.getElementById('superior_department').value = JSONObject[String(treeNode.id)][1];
    // 给部门负责人赋值
    document.getElementById('principal').value = JSONObject[String(treeNode.id)][2];
    // 删除按钮添加删除功能
    document.getElementById("delete-dep").setAttribute("onclick", "del_dep("+String(treeNode.id)+")")
}

// 控制表单、流程导航
function Control_navigation(ele_id) {
    if (ele_id === "create-menu") {
        document.getElementById(ele_id).className = "basic basic-tabs";
        document.getElementById("flow-status").className = "basic";
        document.getElementById("menu_from").style.display = "inline-block";
        document.getElementById("process_status").style.display = "none";
    }else {
        document.getElementById(ele_id).className = "basic basic-tabs";
        document.getElementById("create-menu").className = "basic";
        document.getElementById("process_status").style.display = "inline-block";
        document.getElementById("menu_from").style.display = "none";
    }
}

// function SetIssueEdit0() {
//     var A0 = document.getElementById('A0')
//     var B0 = document.getElementById('B0')
//     A0.onmouseover = function () {
//         B0.style.visibility = 'visible'
//     }
//     A0.onmouseout = function () {
//         B0.style.visibility = 'hidden'
//     }
// }
// function SetIssueTitleEdit0() {
//     var receive_a = document.getElementById("a");
//     receive_a.style.display = 'block';
//     var receive_c = document.getElementById("c");
//     receive_c.style.display = 'block';
//     var receive_e = document.getElementById("e");
//     receive_e.style.display = 'block';
//     var receive_g = document.getElementById("g");
//     receive_g.style.display = 'block';
//     c_number()
// }
//
//
// function SetIssueEdit1() {
//     var a = document.getElementById('a')
//     var b = document.getElementById('b')
//     a.onmouseover = function () {
//         b.style.display = 'inline'
//     }
//     a.onmouseout = function () {
//         b.style.display = 'none'
//     }
// }
// function f() {
//      return textbus.createEditor(document.getElementById('summernote'));
// }
// function SetIssueTitleEdit1() {
//     var receive = document.getElementById("receive");
//     receive.style.display = 'block';
//     var issue_sketch_text = document.getElementById("issue_sketch_text");
//     issue_sketch_text.style.display = 'none';
//     try{
//         console.log('editor:',editor)
//     }
//     catch (e) {
//         editor = f()
//     }
//
//
// }
// function SaveTitle() {
//      var receive = document.getElementById("receive");
//      var issue_sketch_text = document.getElementById("issue_sketch_text");
//      receive.style.display = 'none';
//      issue_sketch_text.innerHTML = editor.getContents().content.replaceAll("%26nbsp", "&nbsp");
//      issue_sketch_text.style.display = 'block';
// }
//
// function SetIssueEdit2() {
//     var c = document.getElementById('c')
//     var d = document.getElementById('d')
//     var del2 = document.getElementById('del2')
//     c.onmouseover = function () {
//         d.style.display = 'inline'
//         del2.style.display = 'inline'
//     }
//     c.onmouseout = function () {
//         d.style.display = 'none'
//         del2.style.display = 'none'
//     }
//
// }
// function SetIssueTitleEdit2() {
//     var receive2 = document.getElementById("receive2");
//     receive2.style.display = 'block';
//     var issue_sketch_text2 = document.getElementById("issue_sketch_text2");
//     issue_sketch_text2.style.display = 'none';
//     try{
//         console.log('editor2:',editor2)
//     }
//     catch (e) {
//         editor2 = f2()
//     }
// }
// function DelIssueTitleEdit2() {
//     var receive2 = document.getElementById("receive2");
//     receive2.style.display = 'none';
//     var issue_sketch_text2 = document.getElementById("issue_sketch_text2");
//     issue_sketch_text2.style.display = 'none';
//     var C = document.getElementById("c");
//     C.style.display = 'none';
//     c_number()
// }
// function SaveTitle2() {
//      var receive2 = document.getElementById("receive2");
//      var issue_sketch_text2 = document.getElementById("issue_sketch_text2");
//      receive2.style.display = 'none';
//      issue_sketch_text2.innerHTML = editor_html2 = editor2.getContents().content.replaceAll("%26nbsp", "&nbsp");
//      issue_sketch_text2.style.display = 'block';
// }
// function f2() {
//      return  textbus.createEditor(document.getElementById('summernote2'));
// }
//
// function SetIssueEdit3() {
//     var e = document.getElementById('e')
//     var f = document.getElementById('f')
//     var del3 = document.getElementById('del3')
//     e.onmouseover = function () {
//         f.style.display = 'inline'
//         del3.style.display = 'inline'
//     }
//     e.onmouseout = function () {
//         f.style.display = 'none'
//         del3.style.display = 'none'
//     }
//
// }
// function SetIssueTitleEdit3() {
//     var receive3 = document.getElementById("receive3");
//     receive3.style.display = 'block';
//     var issue_sketch_text3 = document.getElementById("issue_sketch_text3");
//     issue_sketch_text3.style.display = 'none';
//     try{
//         console.log('editor3:',editor3)
//     }
//     catch (e) {
//         editor3 = f3()
//     }
//
//
// }
// function SaveTitle3() {
//      var receive3 = document.getElementById("receive3");
//      var issue_sketch_text3 = document.getElementById("issue_sketch_text3");
//      receive3.style.display = 'none';
//     issue_sketch_text3.innerHTML = editor3.getContents().content.replaceAll("%26nbsp", "&nbsp");
//     issue_sketch_text3.style.display = 'block';
// }
// function f3() {
//      return textbus.createEditor(document.getElementById('summernote3'));
// }
// function DelIssueTitleEdit3() {
//     var receive3 = document.getElementById("receive3");
//     receive3.style.display = 'none';
//     var issue_sketch_text3 = document.getElementById("issue_sketch_text3");
//     issue_sketch_text3.style.display = 'none';
//     var e = document.getElementById("e");
//     e.style.display = 'none';
//     c_number()
// }
//
// function SetIssueEdit4() {
//     var g = document.getElementById('g')
//     var h = document.getElementById('h')
//     var del4 = document.getElementById('del4')
//     g.onmouseover = function () {
//         h.style.display = 'inline'
//         del4.style.display = 'inline'
//     }
//     g.onmouseout = function () {
//         h.style.display = 'none'
//         del4.style.display = 'none'
//     }
//
// }
// function SetIssueTitleEdit4() {
//     var receive4 = document.getElementById("receive4");
//     receive4.style.display = 'block';
//     var issue_sketch_text4 = document.getElementById("issue_sketch_text4");
//     issue_sketch_text4.style.display = 'none';
//     try{
//         console.log('editor4:',editor4)
//     }
//     catch (e) {
//         editor4 = f4()
//     }
//
//
// }
// function SaveTitle4() {
//      var receive4 = document.getElementById("receive4");
//      var issue_sketch_text4 = document.getElementById("issue_sketch_text4");
//      receive4.style.display = 'none';
//      issue_sketch_text4.innerHTML = editor_html4 = editor4.getContents().content.replaceAll("%26nbsp", "&nbsp");
//      issue_sketch_text4.style.display = 'block';
// }
// function f4() {
//     return textbus.createEditor(document.getElementById('summernote4'));
// }
// function DelIssueTitleEdit4() {
//     var receive4 = document.getElementById("receive4");
//     receive4.style.display = 'none';
//     var issue_sketch_text4 = document.getElementById("issue_sketch_text4");
//     issue_sketch_text4.style.display = 'none';
//     var g = document.getElementById("g");
//     g.style.display = 'none';
//     c_number()
// }
//
// // 更新序号
// function c_number() {
//     var c_number_li = document.getElementsByClassName('SerialNumber')
//     var c_number = 0
//     var arr = new Array()
//     for (var d=0;d<c_number_li.length;d++){
//         ser_id = 'SerialNumber' + (d+1)
//         if (c_number_li[d].style.display ==='none') {
//             c_number = c_number +1
//         }
//         else{
//             arr.push(ser_id)
//         }
//     }
//     for (var i=0;i<arr.length;i++){
//         var er_id2 = arr[i]
//         er_id2_obj = document.getElementById(er_id2)
//         if (i===0){
//             er_id2_obj.innerText = '一'
//         }
//         else if(i===1){
//             er_id2_obj.innerText = '二'
//         }
//         else if(i===2){
//             er_id2_obj.innerText = '三'
//         }
//         else if(i===3){
//             er_id2_obj.innerText = '四'
//         }
//     }
// }

function create_file_table(json_data) {
    var t_table = document.getElementById("t_table");
    deltr();
    for (var i=0; i<json_data.length; i++) {
        var tr = document.createElement("tr");
        var td = document.createElement("td");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");
        var td5 = document.createElement("td");var td6 = document.createElement("td");
        td.innerHTML = i+1;td2.title = i+1;td.style.textAlign = "center";
        td1.innerHTML = "<a target='_blank' href="+json_data[i]['download_path']+">"+json_data[i]['file_name']+"";td1.title = json_data[i]["file_name"];td1.style.textAlign = "center";
        td2.innerHTML = json_data[i]["file_size"];td2.title = json_data[i]["file_size"];td2.style.textAlign = "center";
        td3.innerHTML = json_data[i]["uploader"];td3.title = json_data[i]["uploader"];td3.style.textAlign = "center";
        td4.innerHTML = json_data[i]["create_time"];td4.title = json_data[i]["create_time"];td4.style.textAlign = "center";
        td5.innerHTML = json_data[i]["file_type"];td5.title = json_data[i]["file_type"];td5.style.textAlign = "center";
        td6.innerHTML = "<a target='_blank' href='"+json_data[i]["file_path"]+"' id='"+json_data[i]["id"]+"'>查看 </a> | <a href='#' id='"+json_data[i]["id"]+"' onclick='Confirm_delete2(this.id)' data-toggle=\"modal\" data-target=\".bd-example-modal-sm\"> 删除</a>";td6.style.textAlign = "center";
        tr.appendChild(td);tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
        t_table.appendChild(tr);
    }
}

function delete_news(ele_id) {
    document.getElementById("close-model2").click();
    var page = '1'
    var issue_number = document.getElementById("issue_number").innerHTML;
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('GET', "/administrative/upload_issue_file.html?"+"&delete_list="+String(ele_id)+"&issue_number="+String(issue_number), true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                if(JsonDate['code']===200){
                    create_file_table(JsonDate["data"]['data_li']);
                }
                else{
                    alert(JsonDate['status'])
                }

            }
        }
    };
}


function upload_issue_file1() {
    var form = new FormData();
    var files1 = document.getElementById("accessory1").files[0];
    var issue_number = document.getElementById("issue_number").innerHTML;
    form.append("file1", files1);
    form.append("issue_number", issue_number);

    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/administrative/upload_issue_file.html", true);
    xhr.send(form);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                if (JsonDate["code"] ===200){
                    create_file_table(JsonDate["data"]['data_li'])
                }
                else {
                    alert(JsonDate["status"])
                }
            }
        }
    };
}


function upload_issue_file2() {
    var form = new FormData();
    var files2 = document.getElementById("accessory2").files[0];
    var issue_number = document.getElementById("issue_number").innerHTML;
    form.append("file2", files2);
    form.append("issue_number", issue_number);

    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/administrative/upload_issue_file.html", true);
    xhr.send(form);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                if (JsonDate["code"] ===200){
                    create_file_table(JsonDate["data"]['data_li'])
                }
                else {
                    alert(JsonDate['status'])
                }
            }
        }
    };
}

function Confirm_delete2(ele_id) {
    document.getElementById("countersign").setAttribute("onclick", "delete_news("+ele_id+")");
    var myArray = new Array();
    var check_box_list = document.getElementsByClassName("check_box");
    for (var t = 0; t < check_box_list.length; t++) {
        if (check_box_list[t].checked) {
            myArray.push(check_box_list[t].id)
        }
    }
    document.getElementById("Confirm-content").innerHTML = "<i style='color: #1E90FF;font-size: 50px;vertical-align:middle;' class=\"iconfont icon-jinggao-chucuo\"></i> <span>确认要删除这此文件吗？</span>"
}

function deltr(){
    var tb = document.getElementById('t_table');
    var rowNum=tb.rows.length;
    for (i=0;i<rowNum;i++) {
        tb.deleteRow(i);
        rowNum=rowNum-1;
        i=i-1;
    }
}


function co_mouse_on(co_id) {
    document.getElementById(co_id+'_chose').style.display = 'inline-block'
    document.getElementById(co_id+'_del').style.display = 'inline-block'
    // document.getElementById(co_id).innerHTML = '<div>'+co_text+'</div>'
}

function co_mouse_out(co_id) {
    document.getElementById(co_id+'_chose').style.display = 'none'
    document.getElementById(co_id+'_del').style.display = 'none'
}

function del_co(co_department_id) {
    console.log('co_id:',co_department_id)
    co_text = document.getElementById(co_department_id).innerHTML
    document.getElementById(co_department_id+'_chose').style.display = 'none'
    document.getElementById(co_department_id+'_del').style.display = 'none'
    console.log('co_text:',co_text)
    document.getElementById(co_department_id).innerHTML = ''+"<div id='"+co_department_id+"_chose' style=\"color:blue;display: none\"  data-toggle=\"modal\" data-target=\".bd-example-modal-xl\" onclick=\"delete_val('"+co_department_id+"')\">\n" +
    "                                        选择\n" +
    "                                    </div>\n" +
    "\n" +
    "                                    <div id='"+co_department_id+"_del' style=\"display: none\" onclick=\"del_co('"+co_department_id+"')\">\n" +
    "                                        删除\n" +
    "                                    </div>";
}
